#include "b_config.h"
#include "hal/inc/b_hal_lcd.h"
#include "b_os.h"

/**
 * \addtogroup B_HAL
 * \{
 */

/**
 * \addtogroup LCD
 * \{
 */

/**
 * \defgroup LCD_Private_Variables
 * \{
 */

static bLcdConfig_t s_lcd_config;

/**
 * \}
 */

/**
 * \defgroup LCD_Private_Functions
 * \{
 */

/**
 * \}
 */

/**
 * \defgroup LCD_Exported_Functions
 * \{
 */

int bHalLcdInit(bLcdConfig_t *config)
{
    if (config == NULL)
        return -1;

    // Save configuration
    s_lcd_config = *config;

    // Initialize MCU-specific LCD
    return bMcuLcdInit(config);
}

int bHalLcdDeInit(void)
{
    return bMcuLcdDeInit();
}

int bHalLcdOn(void)
{
    return bMcuLcdOn();
}

int bHalLcdOff(void)
{
    return bMcuLcdOff();
}

int bHalLcdSetContrast(uint8_t contrast)
{
    if (contrast > 100)
        return -1;

    s_lcd_config.contrast = contrast;
    return bMcuLcdSetContrast(contrast);
}

int bHalLcdClear(void)
{
    return bMcuLcdClear();
}
int bHalLcdSetAllSeg(uint8_t state)
{
    for(int i = 0; i < LCD_SEG_MAX; i++)
    {
        bHalLcdSetSeg(i, LCD_COM_0, state);
        bHalLcdSetSeg(i, LCD_COM_1, state);
        bHalLcdSetSeg(i, LCD_COM_2, state);
        bHalLcdSetSeg(i, LCD_COM_3, state);
    }
}
int bHalLcdSetSeg(bLcdSeg_t seg, bLcdCom_t com, uint8_t state)
{
    if (seg >= LCD_SEG_MAX || com >= LCD_COM_MAX)
        return -1;

    return bMcuLcdSetSeg(seg, com, state);
}
uint8_t bHalLcdReadSegState(bLcdSeg_t seg, bLcdCom_t com)
{
    if (seg >= LCD_SEG_MAX || com >= LCD_COM_MAX)
        return -1;

    return bMcuLcdReadSegState(seg, com);
}

/**
 * \}
 */

/**
 * \}
 */

/**
 * \}
 */

/************************ Copyright (c) 2024 Bean *****END OF FILE****/ 